package com.hexacta.hrs.test.data;

import static com.hexacta.hrs.test.data.CompanyTestDataDependencyCreator.HEXACTA_COMPANY;
import static com.hexacta.hrs.test.data.JobTermTestDataDependencyCreator.UNASSIGNED_JOB_TERM;
import static com.hexacta.hrs.test.data.PersonTestDataDependencyCreator.*;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.vectrics.company.Company;
import org.vectrics.employee.Employee;
import org.vectrics.recruiter.job.JobTerm;
import org.vectrics.user.Person;

/**
 * Test data creator for an Employee.
 * 
 * @author tpollak
 */
public class EmployeeTestDataCreator extends AbstractTestDataCreator {

    @Resource
    private TestDataDependencyCreator personTDDC;

    public EmployeeTestDataCreator(final List<TestDataDependencyCreator> dependencies) {
        super(dependencies);
    }

    @Override
    protected Object internalCreateTestData(final Map<String, Object> context) {
        Employee employee = createEmployeeAdmin(context);
        return employee;
    }

    private Employee createEmployeeAdmin(final Map<String, Object> context) {
        Person admin = (Person) loadObjectFromContext(context, ADMIN_PERSON);
        return createEmployee(context, admin);
    }

    public void createPersonTestData(final Map<String, Object> context) {
        personTDDC.createDependentTestData(context);
    }

    public Employee createEmployeePerson1(final Map<String, Object> context) {
        Person admin = (Person) loadObjectFromContext(context, PERSON_1);
        return createEmployee(context, admin);
    }

    public Employee createEmployeePerson2(final Map<String, Object> context) {
        Person admin = (Person) loadObjectFromContext(context, PERSON_2);
        return createEmployee(context, admin);
    }

    public Employee createEmployeePerson3(final Map<String, Object> context) {
        Person admin = (Person) loadObjectFromContext(context, PERSON_3);
        return createEmployee(context, admin);
    }

    public Employee createEmployee(final Map<String, Object> context, final Person person) {
        Company hexacta = (Company) loadObjectFromContext(context, HEXACTA_COMPANY);
        JobTerm term = (JobTerm) loadObjectFromContext(context, UNASSIGNED_JOB_TERM);
        return getDataUtils().createEmployee(context, hexacta, person, person, term);
    }

}
